home *** CD-ROM | disk | FTP | other *** search
- /* srand.c from page 245*/
- #include <stdio.h>
- #include <stdlib.h>
- main()
- {
- int i;
- unsigned seed;
- printf("Enter a seed: "); /*ask user to enter a new seed*/
- scanf("%u", &seed);
- srand(seed); /*set new seed by calling "srand" */
-
- /* Generate and display 20 pseudorandom integers */
- printf("20 pseudorandom integers from \"rand\"\n");
- for(i = 0; i < 20; i++)
- {
- printf("%d\n", rand());
- }
- printf("Try again with the same seed.\n\
- you'll get the same sequence.\n");
- }
-